<template>
    <view class="container">
        <view class="logo">
            <image class="logo-img" src="/static/logo.png" @click="tikFn()"></image>
            <text>您好，欢迎登录！</text>
        </view>

        <view class="login-way">
            <view class="tab">
                <view class="tab-box">
                    <view class="tab-item" @click="clickTab(index)" v-for="(item, index) in tabs"
                        :class="{ current: tabIndex == index, 'right-current': index == 1 }" :key="index">
                        <text>{{ item.title }}</text>
                        <view class="bg"></view>
                    </view>
                </view>
                <view class="tab-bg"></view>
            </view>
            <view class="login-way-main">
                <login-admin v-show="tabIndex == 0"></login-admin>
                <login-supply v-show="tabIndex == 1"></login-supply>
            </view>
        </view>
        <view class="bei-an">1闽ICP备15022977号-18A</view>
        <!-- 切换环境 -->
        <uni-popup ref="popServe" type="bottom" background-color="#fff" :safe-area="false">
            <view class="bottom-pop">
                <text class="title">切换环境</text>
                <view class="actions">
                    <button class="btn btn-gray-hollow" @click="selectServer(1)">正式</button>
                    <button class="btn btn-gray-hollow" @click="selectServer(9)">测试</button>
                </view>
            </view>
        </uni-popup>
    </view>
</template>

<script>
import storage from "@/uni-sub-base/utils/storage.js"
import config from "@/config/config.js"
import loginAdmin from "@/components/login/login-admin.vue"
import loginSupply from "@/components/login/login-supply.vue"

export default {
    components: {
        loginAdmin,
        loginSupply,
    },
    data() {
        return {
            tikNum: 0,
            tabIndex: 0,
            tabs: [
                {
                    type: 1,
                    title: "企业端",
                },
                {
                    type: 2,
                    title: "供应端",
                },
            ],
        }
    },
    onLoad(e) { },
    mounted() { },
    methods: {
        //tab切换
        clickTab(index) {
            if (this.tabIndex != index) {
                this.tabIndex = index
            }
        },
        tikFn() {
            this.tikNum += 1
            if (this.tikNum >= 10) {
                //弹窗切换环境
                this.$refs.popServe.open()
            }
        },
        selectServer(type) {
            //1正式 0 测试
            storage.setCache("appService", type)
            this.doLogout()
        },
        //退出登录
        doLogout() {
            this.tikNum = 0
            setTimeout(() => {
                this.easyReLaunch("/pages/login/index")
            }, 300)
        },
    },
}
</script>

<style lang="scss" scoped>
page {
    background: #f5f6f9;
}

.container {
    padding: 140rpx 0rpx 0;
}

.login-way {
    padding: 40rpx 40rpx 0;
}

.logo {
    display: flex;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    padding: 6rpx;

    .logo-img {
        width: 140rpx;
        height: 140rpx;
        display: block;
        border-radius: 20rpx;
        padding: 0;
        margin-bottom: 24rpx;
    }

    text {
        font-size: $font-size-40;
        font-weight: bold;
    }
}

.title {
    font-size: 36rpx;
    padding-left: 24rpx;
}

.tab {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    position: relative;
    display: flex;
    flex: 1;
    z-index: 0;

    .tab-box {
        display: flex;
        flex-direction: row;
        align-items: flex-end;
        flex: 1;
        height: 86rpx;
        perspective: 1000;
        z-index: 1;
    }

    .tab-bg {
        position: absolute;
        width: 100%;
        left: 0%;
        right: 2%;
        bottom: 0;
        z-index: 0;
        height: 82rpx;
        background: #e8ecf9;
        border-radius: 24rpx 24rpx 0 0;
        border-bottom: solid 1px #dfe3ef;
    }

    .tab-item {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 76rpx;
        min-width: 45%;
        padding-bottom: 6rpx;

        &:first-child {
            border-radius: 24rpx 0 0 0;
        }

        &:last-child {
            border-radius: 0 24rpx 0 0;
        }

        text {
            color: $app-color-text-desc;
            position: relative;
            z-index: 1;
            font-size: $font-size-30;
        }
    }

    .current {
        height: 86rpx;
        overflow: hidden;
        position: relative;
        background: rgba(0, 0, 0, 0);
        width: 150%;

        text {
            color: $app-color-main;
            font-weight: 700;
        }

        .bg {
            position: absolute;
            left: 0;
            top: 0;
            z-index: 0;
            width: 88%;
            height: 86rpx;
            /* 宽高 */
            background-color: #ffffff;
            /* 颜色 */
            // padding: 4rpx 10rpx;
            border-radius: 24rpx 18rpx 0 0;
            box-shadow: 0px 0px 7px 0px rgba(185, 192, 208, 0.4);
            /* 设置圆角 */
            transform: perspective(12rpx) rotateX(1deg);
            /* 镜头距离元素表面的位置为8px，x轴为1.1倍y轴为1.3倍，绕x轴旋转5度 */
            transform-origin: 0 0;
            /* bottom left = left bottom = 0 100% 中心点偏移量*/
        }
    }

    .right-current {
        .bg {
            margin-left: 12%;
            border-radius: 18rpx 24rpx 0 0;
            // transform: perspective(5rpx) rotateX(1deg);
            /* 镜头距离元素表面的位置为8px，x轴为1.1倍y轴为1.3倍，绕x轴旋转5度 */
            transform-origin: right 0;
        }
    }
}

.bei-an {
    // position: fixed;
    bottom: 24rpx;
    text-align: center;
    width: 100%;
    left: 0;
    padding: 20rpx 0 40rpx 0;
}
</style>
